using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json.Linq;

namespace JsonRpcGen.TypeHandler
{
    internal class ArrayTypeHandler : ObjectTypeHandler
    {
        private readonly JToken _items;
        private ObjectTypeHandler _itemTypeHandler;

        public ArrayTypeHandler(JToken items):base(items["properties"])
        {
            _items = items;
        }

        public override void Write(StreamWriter writer, string namesp, string className, Dictionary<string, string> replacements)
        {
            if (_items["properties"] == null)
                return;
            writer.WriteLine("using System.Collections.Generic;");
            writer.WriteLine("namespace " + namesp);
            writer.WriteLine("{");
            WriteClass(writer, className+"Item", replacements);
            WriteArray(writer, className);
            writer.WriteLine("}");
        }

        public void WriteArray(StreamWriter writer, string className)
        {
            writer.Write("   public class " + className + " : List<" + className + "Item>");
            writer.WriteLine();

            writer.WriteLine("   {");
            writer.WriteLine("   }");
        }
    }
}